package com.fdb.efp.cus.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import com.fdb.efp.cus.service.dao.CusRelCheckDao;
import com.fdb.efp.cus.service.domain.CusRelCheck;
import com.fdb.basic.framework.core.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.efp.cus.service.facade.CusRelCheckService;
import com.fdb.efp.cus.service.vo.CusRelCheckVO;
import com.alibaba.fastjson.JSON;
import com.fdb.basic.framework.core.base.AbstractFrameworkService;
import com.fdb.basic.framework.core.base.FrameworkService;
/**
 * @description:行内员工信息
 * @date:2018年12月27日 上午11:18:53
 * @author:wangyk3
 */
@Service("cusRelCheckService")
public class CusRelCheckServiceImpl extends AbstractFrameworkService implements CusRelCheckService, FrameworkService {
	private static Logger logger = LoggerFactory.getLogger(CusRelCheckServiceImpl.class);
	
	
	@Autowired
	private CusRelCheckDao cusRelCheckDao;
	
	/**
	 * 查询关联人信息
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<CusRelCheckVO> queryCusRelCheckList(CusRelCheckVO cusRelCheckVO) {
		logger.info("查询关联人信息开始......");
		CusRelCheck cusRelCheck = beanCopy(cusRelCheckVO, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryCusRelCheckList(cusRelCheck);
			logger.info("查询到关联人信息的结果集数量为:" + cusRelChecks.size());
			pageSet(cusRelChecks, cusRelCheck);
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		logger.info("查询关联人信息结束......");
		return list;
	}
	
	
	
	/**
	 * 查询用户权限数据
	 */
	/*@SuppressWarnings("unchecked")
	@Override
	public List<CusRelCheckVO> queryAllOwner(CusRelCheckVO cusRelCheckVO) {
		logger.info("当前查询本人所属数据信息的参数信息为:");
		CusRelCheck cusRelCheck = beanCopy(cusRelCheckVO, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryAllOwnerByPage(cusRelCheck);
			logger.info("当前查询本人所属数据信息的结果集数量为:" + cusRelChecks.size());
			pageSet(cusRelChecks, cusRelCheck);
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}*/
	
	/**
	 * 查询当前机构权限数据
	 */
	/*@SuppressWarnings("unchecked")
	@Override
	public List<CusRelCheckVO> queryAllCurrOrg(CusRelCheckVO cusRelCheckVO) {
		logger.info("当前查询本人所属数据信息的参数信息为:");
		CusRelCheck cusRelCheck = beanCopy(cusRelCheckVO, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryAllCurrOrgByPage(cusRelCheck);
			logger.info("当前查询本人所属数据信息的结果集数量为:" + cusRelChecks.size());
			pageSet(cusRelChecks, cusRelCheck);
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}*/
	
	/**
	 * 查询当前机构及下属机构权限数据
	 */
	/*@SuppressWarnings("unchecked")
	@Override
	public List<CusRelCheckVO> queryAllCurrDownOrg(CusRelCheckVO cusRelCheckVO) {
		logger.info("当前查询本人所属数据信息的参数信息为:");
		CusRelCheck cusRelCheck = beanCopy(cusRelCheckVO, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryAllCurrDownOrgByPage(cusRelCheck);
			logger.info("当前查询本人所属数据信息的结果集数量为:" + cusRelChecks.size());
			pageSet(cusRelChecks, cusRelCheck);
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}*/
	
	/**
	 * @description:插入行内员工信息
	 * @param CusRelCheckVO
	 * @return
	 * @date:2018年12月27日 上午11:23:16
	 * @author:wangyk3
	 */
	@Override
	public int insertCusRelCheck(CusRelCheckVO cusRelCheckVO) {
		logger.debug("当前新增数据为:"+ cusRelCheckVO.toString());
		CusRelCheck cusRelCheck = new CusRelCheck();
		int num = 0;
		try {
			beanCopy(cusRelCheckVO, cusRelCheck);
			num = cusRelCheckDao.insertCusRelCheck(cusRelCheck);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}
	
	/**
	 * @description:批量插入关系人信息表
	 * @param cusRelCheckVO
	 * @return
	 * @date:2019年1月20日 下午12:51:38
	 * @author:wangyk3
	 */
	@SuppressWarnings("unchecked")
	@Override
	public int insertCusRelCheckBatch(List<CusRelCheckVO> cusRelCheckVOList) {
		logger.debug("当前新增数据条数为:"+ cusRelCheckVOList.size());
		List<CusRelCheck> cusRelCheckList = new ArrayList<CusRelCheck>();
		int num = 0;
		try {
			cusRelCheckList = (List<CusRelCheck>)beansCopy(cusRelCheckVOList, CusRelCheck.class);
			num = cusRelCheckDao.insertCusRelCheckBatch(cusRelCheckList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}
	
	/**
	 * @description:批量更新关联人信息
	 * @param list
	 * @return
	 * @date:2019年1月20日 下午4:12:54
	 * @author:wangyk3
	 */
	@SuppressWarnings("unchecked")
	@Override
	public int updateCusRelCheckBatch(List<CusRelCheckVO> list) {
		logger.debug("当前修改数据为:"+ list.size() + "条");
		List<CusRelCheck> cusRelCheckList = new ArrayList<CusRelCheck>();
		int num = 0;
		try {
			cusRelCheckList = (List<CusRelCheck>)beansCopy(list, CusRelCheck.class);
			num = cusRelCheckDao.updateCusRelCheckBatch(cusRelCheckList);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("修改的数据条数为"+ num);
		return num;
	}
	/**
	 * @description:根据证件号码，证件类型查询行内员工信息
	 * @param certCode
	 * @return
	 * @date:2018年12月27日 下午2:54:00
	 * @author:wangyk3
	 */
	@Override
	public CusRelCheckVO queryCusRelCheckBycertCode(String certCode, String certType) throws Exception{
		logger.debug("当前查询参数信息为:"+ certCode);
		CusRelCheck cusRelCheck = new CusRelCheck();
		try {
			cusRelCheck = cusRelCheckDao.queryCusRelCheckBycertCode(certCode, certType);
			if (Objects.nonNull(cusRelCheck)) {
				CusRelCheckVO cusRelCheckVO = beanCopy(cusRelCheck, new CusRelCheckVO());
				logger.debug("当前查询结果为:"+ cusRelCheckVO.toString());
				return cusRelCheckVO;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}
	@Override
	public List<CusRelCheckVO> queryConditions(String certCode, String certType) {
		logger.debug("当前查询参数信息为:"+ certCode);
		List<CusRelCheck> cusRelCheck = null;
		try {
			cusRelCheck = cusRelCheckDao.queryConditions(certCode, certType);
			if (Objects.nonNull(cusRelCheck)) {
				List<CusRelCheckVO> cusRelCheckVO = (List<CusRelCheckVO>) beansCopy(cusRelCheck, CusRelCheckVO.class);
				logger.debug("当前查询结果为:"+ cusRelCheckVO.toString());
				return cusRelCheckVO;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
	/**
	 * @description:更新行内人员信息
	 * @param CusRelCheckVO
	 * @return
	 * @date:2018年12月27日 下午7:30:11
	 * @author:wangyk3
	 */
	@Override
	public int updateCusRelCheck(CusRelCheckVO cusRelCheckVO) {
		logger.debug("当前修改数据为:"+ cusRelCheckVO.toString());
		CusRelCheck cusRelCheck = null;
		int num = 0;
		try {
			cusRelCheck = new CusRelCheck();
			beanCopy(cusRelCheckVO, cusRelCheck);
			num = cusRelCheckDao.updateCusRelCheck(cusRelCheck);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ cusRelCheckVO +"修改的数据条数为"+ num);
		return num;
	}
	/**
	 * @description:根据主键查询关联人信息
	 * @param cusRelCheckVO
	 * @return
	 * @date:2018年12月27日 下午9:49:45
	 * @author:wangyk3
	 */
	@Override
	public CusRelCheckVO queryCusRelCheckBypk(CusRelCheckVO cusRelCheckVO) {
		
		logger.debug("当前查询参数信息为:"+ cusRelCheckVO.toString());
		try {
			CusRelCheck cusRelCheck = new CusRelCheck();
			beanCopy(cusRelCheckVO, cusRelCheck);
			CusRelCheck cusRelCheck2 = cusRelCheckDao.queryByPk(cusRelCheck);
			if (Objects.nonNull(cusRelCheck2)) {
				CusRelCheckVO cusRelCheckVO2 = beanCopy(cusRelCheck2, new CusRelCheckVO());
				logger.debug("当前查询结果为:"+ cusRelCheckVO2.toString());
				return cusRelCheckVO2;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
	@Override
	public int updateByPk(CusRelCheckVO cusRelCheckVO) {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * @description:根据主键删除关联人信息
	 * @param cusRelCheckVO
	 * @return
	 * @date:2018年12月27日 下午9:32:27
	 * @author:wangyk3
	 */
	@Override
	public int deleteByPk(CusRelCheckVO cusRelCheckVO) {
		logger.debug("当前删除数据条件为:"+ cusRelCheckVO.toString());
		int num = 0;
		try {
			CusRelCheck cusrelcheck = new CusRelCheck();
			beanCopy(cusRelCheckVO, cusrelcheck);
			num = cusRelCheckDao.deleteByPk(cusrelcheck);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ cusRelCheckVO.toString() +"删除的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 分页查询关联人信息
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<CusRelCheckVO> queryCusRelCheckPageInfo(CusRelCheckVO cusRelCheckVO) {
		logger.info("查询关联人信息开始......");
		CusRelCheck cusRelCheck = beanCopy(cusRelCheckVO, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryCusRelCheckByPage(cusRelCheck);
			logger.info("查询到关联人信息的结果集数量为:" + cusRelChecks.size());
			pageSet(cusRelChecks, cusRelCheck);
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		logger.info("查询关联人信息结束......");
		return list;
	}

	@Override
	public int insertCusRelCheckExp(CusRelCheckVO cusRelCheckVO) throws Exception {
		logger.debug("当前新增数据为：" + JSON.toJSONString(cusRelCheckVO));
		CusRelCheck cusRelCheck = new CusRelCheck();
		int num = 0;
		try {
			beanCopy(cusRelCheckVO, cusRelCheck);
			num = cusRelCheckDao.insertCusRelCheck(cusRelCheck);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为： "+ num);
		return num;
	}

	@Override
	public int batchDeleteByPk(CusRelCheckVO cusRelCheckVo) {
		logger.debug("当前删除数据条件为:"+ cusRelCheckVo);
		int num = 0;
		try {
			List<String> relSernoList = null;
			if (Objects.nonNull(cusRelCheckVo) && !StringUtil.isNullorBank(cusRelCheckVo.getRelSerno())) {
				relSernoList = Arrays.asList(cusRelCheckVo.getRelSerno().split(","));
			}
			num = cusRelCheckDao.batchDeleteByPk(relSernoList);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		return num;
	}

	@Override
	public List<CusRelCheckVO> queryExCusRelCheckPageInfo(CusRelCheckVO vo) {
		logger.info("查询关联人信息开始......");
		CusRelCheck cusRelCheck = beanCopy(vo, new CusRelCheck());
		List<CusRelCheckVO> list = null;
		try {
			List<CusRelCheck> cusRelChecks = cusRelCheckDao.queryExCusRelCheckPageInfo(cusRelCheck);
			logger.info("查询到关联人信息的结果集数量为:" + cusRelChecks.size());
			list = (List<CusRelCheckVO>) beansCopy(cusRelChecks, CusRelCheckVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		logger.info("查询关联人信息结束......");
		return list;
	}

	@Override
	public int batchInsertRelCheck(List<CusRelCheckVO> inserCusRelCkstBatch) {
		logger.debug("当前新增数据条数为:"+ inserCusRelCkstBatch.size());
		int num = 0;
		try {
			num = cusRelCheckDao.batchInsertRelCheck(inserCusRelCkstBatch);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		return num;
	}

}
